﻿@model IEnumerable<WebBarracoDoSom.Models.Instrumento>

@{
    ViewBag.Title = "Pesquisa de Instrumentos";
}

<h2>Pesquisar Instrumentos</h2>

<p>
    @using (Html.BeginForm()){   
         <p>Categoria: @Html.DropDownList("instrumentoCateg", new SelectList(WebBarracoDoSom.Models.Categoria.Categorias, "ID", "Nome"), "All")</p>
         <p>Nome: @Html.TextBox("nomeString")</p>
         <p><input type="submit" value="Filtrar" /></p>
    }
</p>

<table>
    <tr>
        <th align="center">
            Nome
        </th>
        <th align="center">
            Categoria
        </th>
        <th align="center">
            Marca
        </th>
        <th align="center">
            Descricao
        </th>
        <th align=center>
            Preço
        </th>

        <th align="center">
            Foto
        </th>
        
        <th align="center">
            Alugado
        </th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td align="center">
            @Html.DisplayFor(modelItem => item.Nome)
        </td>

       <td align="center">
            @WebBarracoDoSom.Models.Categoria.Categorias.ElementAt(item.Categoria_ID).Nome
        </td>

        <td align="center">
            @Html.DisplayFor(modelItem => item.Marca)
        </td>

        <td align="center">
            @Html.DisplayFor(modelItem =>  item.Descricao)
        </td>

        <td align="center">
            @Html.DisplayFor(modelItem => item.Preco)
        </td>

        <td align="center">
            <a href=@Html.DisplayFor(modelItem => item.Foto)>
            <img src=@Html.DisplayFor(modelItem => item.Foto) height="100" width="100" /></a> 
        </td>
        
        <td align="center">
            @if (WebBarracoDoSom.Controllers.EmprestimoController.InstrumentoAlugado(item.ID))
            {
                @Html.Label("Sim");
            }
            else
            {
                @Html.Label("Não");
            }
        </td>
        
        <td align="center">
         @if (Request.IsAuthenticated && (User.Identity.Name == "0" || User.Identity.Name == "1"))
         {
            @Html.ActionLink("Editar", "Edit", new { id = item.ID })
         }
         
         @if (Request.IsAuthenticated && (User.Identity.Name == "0" || User.Identity.Name == "1"))
         {
            @Html.ActionLink("Deletar", "Delete", new { id = item.ID })
         }
         
         @Html.ActionLink("Detalhes", "Details", new { id = item.ID })
         
         @if (Request.IsAuthenticated)
         {
              if (WebBarracoDoSom.Controllers.EmprestimoController.InstrumentoAlugado(item.ID))
              {
                  @Html.ActionLink("Reservar", "SearchIndex")
              }
              else
              {
                  @Html.ActionLink("Alugar", "Create", "Emprestimo", new { instrumentoID = item.ID }, new { instrumentoID = item.ID })
              }
         }
        </td>  
    </tr>
}

</table>